<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>vue</title>
<head>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script charset="utf-8" type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<!--显示-->
<div id="app">
    {{ message }}
</div>
<!--绑定事件-->
<div id="app-2">
            <span v-bind:title="message">
                鼠标悬停几秒钟查看此处动态绑定的提示信息！
            </span>
</div>
<!--判断-->
<div id="app-3">
    <p v-if="seen">看到了</p>
</div>
<!--循环-->
<div id="app-4">
    <ol>
        <li v-for="product in products">
            {{ product.name }}
        </li>
    </ol>
</div>
<!--交互-->
<div id="app-5">
    <p>{{message}}</p>
    <button v-on:click="reverseMessage">反转消息</button>
</div>
<!--绑定-->
<div id="app-6">
    <p>{{message}}</p>
    <input v-model="message"/>
</div>
<!--使用自定义组件-->
<div id="app-7">
    <ol>
        <todo-item v-for="item in groceryList" v-bind:todo="item" v-bind:key="item.id"></todo-item>
    </ol>
</div>
<script charset="utf-8" type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello World!'
        }
    });
    var app2 = new Vue({
        el: '#app-2',
        data: {
            message: '页面加载于 ' + new Date().toLocaleString()
        }
    });
    var app3 = new Vue({
        el: '#app-3',
        data: {
            seen: true
        }
    });
    var app4 = new Vue({
        el: '#app-4',
        data: {
            products: [
                {name: '石榴'},
                {name: '苹果'},
                {name: '无花果'}
            ]
        }
    });

    var app5 = new Vue({
        el: '#app-5',
        data: {
            message: 'Hello World!'
        },
        methods: {
            reverseMessage: function () {
                this.message = this.message.split('').reverse().join('');
            }
        }
    });

    var app6 = new Vue({
        el: '#app-6',
        data: {
            message: 'Hello Input.'
        }
    });

    // 定义名为 todo-item 的新组件
    Vue.component('todo-item', {
        props: ['todo'],
        template: '<li>{{todo.text}}</li>'
    });
    var app7 = new Vue({
        el: '#app-7',
        data: {
            groceryList: [
                {id: 0, text: '蔬菜'},
                {id: 1, text: '奶酪'},
                {id: 2, text: '随便其它什么人吃的东西'}
            ]
        }
    })
</script>
</body>
</html>